home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WINPROGS.ARJ / STATLINE.C < prev    next >
Text File  |  1991-01-11  |  9KB  |  351 lines

  1. /*   Statline.c   -  StatLine ChildWindow Program
  2.                      Norton and Yao
  3. */
  4.  
  5. #include <windows.h>
  6. #include "statline.h"
  7.  
  8.  
  9. static char szAppName[] = "StatLine";
  10.  
  11.  
  12. long FAR PASCAL WndProc  (HWND, WORD, WORD, LONG);
  13. long FAR PASCAL StatLineProc  (HWND, WORD, WORD, LONG);
  14. BOOL FAR PASCAL Test2(HWND, unsigned, WORD, LONG);
  15.  
  16. HWND hwndStat;
  17. int cyChildHeight;
  18.  
  19.  
  20. int PASCAL WinMain (HANDLE hInstance,
  21.                     HANDLE hPrevInstance,
  22.                     LPSTR  lpszCmdParam,
  23.                     int    nCmdShow)
  24.                     
  25.   {
  26.   HWND        hwnd;
  27.   MSG         msg;
  28.   WNDCLASS    wndclass;
  29.  
  30.  
  31.   if (!hPrevInstance)
  32.     {      
  33.      wndclass.style            = NULL;
  34.      wndclass.lpfnWndProc      = WndProc;
  35.      wndclass.cbClsExtra       = 0;
  36.      wndclass.cbWndExtra       = 0;
  37.      wndclass.hInstance        = hInstance;
  38.      wndclass.hIcon            = LoadIcon (NULL, IDI_APPLICATION);
  39.      wndclass.hCursor          = LoadCursor (NULL, IDC_ARROW);
  40.      wndclass.hbrBackground    = COLOR_WINDOW + 1;
  41.      wndclass.lpszMenuName     = "#1";
  42.      wndclass.lpszClassName    = szAppName;
  43.      
  44.      RegisterClass(&wndclass);
  45.  
  46.      wndclass.style            = NULL;
  47.      wndclass.lpfnWndProc      = StatLineProc;
  48.      wndclass.cbClsExtra       = 0;
  49.      wndclass.cbWndExtra       = 0;
  50.      wndclass.hInstance        = hInstance;
  51.      wndclass.hIcon            = NULL;
  52.      wndclass.hCursor          = LoadCursor (NULL, IDC_ARROW);
  53.      wndclass.hbrBackground    = COLOR_WINDOW + 1;
  54.      wndclass.lpszMenuName     = NULL;
  55.      wndclass.lpszClassName    = "StatLineProc";
  56.      
  57.      RegisterClass(&wndclass);
  58.      
  59.  
  60.     }
  61.  
  62.   
  63.   hwnd = CreateWindow (szAppName,
  64.                        "Status Line Program",
  65.                        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  66.                        CW_USEDEFAULT,
  67.                        0,
  68.                        CW_USEDEFAULT,
  69.                        0,
  70.                        NULL,
  71.                        NULL,
  72.                        hInstance,
  73.                        NULL);
  74.                        
  75.                         
  76.   hwndStat = CreateWindow ("StatLineProc",
  77.                            NULL,
  78.                            WS_CHILD | WS_BORDER | WS_VISIBLE,
  79.                            0,
  80.                            0,
  81.                            0,
  82.                            0,
  83.                            hwnd,
  84.                            NULL,
  85.                            hInstance,
  86.                            NULL);
  87.                            
  88.   ShowWindow (hwnd, nCmdShow);       
  89.   
  90.   while (GetMessage (&msg, NULL, 0, 0))
  91.     {
  92.     TranslateMessage (&msg);
  93.     DispatchMessage  (&msg);
  94.     }
  95.     
  96.   return 0;
  97.   }
  98.   
  99. long FAR PASCAL WndProc (HWND hwnd,
  100.                          WORD message,
  101.                          WORD wParam,
  102.                          LONG lParam)
  103.                          
  104.   {
  105.  
  106.     FARPROC lpProcTest2;
  107.  
  108.     int bTest2;
  109.  
  110.   switch (message)
  111.     {
  112.     case WM_CREATE:
  113.       {
  114.       HDC hdc;
  115.       int cyBorder;
  116.       TEXTMETRIC tm;
  117.       
  118.       hdc = GetDC (hwnd);
  119.       GetTextMetrics (hdc,&tm);
  120.       ReleaseDC (hwnd,hdc);
  121.       
  122.       cyBorder = GetSystemMetrics (SM_CYBORDER);
  123.       cyChildHeight = tm.tmHeight + cyBorder * 2;
  124.       }
  125.       break;
  126.       
  127.     case WM_DESTROY:
  128.       PostQuitMessage(0);
  129.       break;
  130.       
  131.       case WM_COMMAND:
  132.         if (wParam == IDM_TONY)
  133.           {
  134.           lpProcTest2 = MakeProcInstance(Test2, hwnd);
  135.           bTest2 = DialogBox(hwnd, "Test2", hwnd, lpProcTest2);
  136.           FreeProcInstance(lpProcTest2);
  137.           if (bTest2)
  138.             MessageBox( GetFocus(),
  139.                         "Dialog OK'ed",
  140.                         "Dialog Response",
  141.                         MB_ICONINFORMATION | MB_OK);
  142.           else
  143.             MessageBox( GetFocus(),
  144.                         "Dialog CANCLED",
  145.                         "Dialog Response",
  146.                         MB_ICONINFORMATION | MB_OK);
  147.         }
  148.         break;
  149.  
  150.    case WM_MENUSELECT:
  151.      SendMessage (hwndStat, message, wParam, lParam);
  152.      break;
  153.      
  154.    case WM_SIZE:
  155.      {
  156.      int cxWidth;
  157.      int cyHeight;
  158.      int xChild;
  159.      int yChild;
  160.      
  161.      cxWidth = LOWORD (lParam);
  162.      cyHeight = HIWORD (lParam);
  163.      
  164.      xChild = 0;
  165.      yChild = cyHeight - cyChildHeight + 1;
  166.      
  167.      MoveWindow (hwndStat,
  168.                  xChild,
  169.                  yChild,
  170.                  cxWidth,
  171.                  cyChildHeight,
  172.                  TRUE);
  173.  
  174.      }
  175.      break;
  176.      
  177.    default:
  178.       return(DefWindowProc (hwnd,message,wParam,lParam));
  179.       break;
  180.    }
  181.  return 0L;
  182.  }
  183.  
  184.              
  185.     
  186. long FAR PASCAL StatLineProc (HWND hwnd,
  187.                               WORD message,
  188.                               WORD wParam,
  189.                               LONG lParam)
  190.                          
  191.   {
  192.  
  193.   static STATUSDATA   sd[COUNT] = 
  194.     { 0xffff, "",
  195.       IDM_SYS,      "Move, size or close application window",
  196.       IDM_FILE,     "Create, open, save, print, or quit",
  197.       IDM_EDIT,     "Undo, cut, copy, paste, and delete",
  198.       
  199.       IDM_NEW,      "Creates a new item",
  200.       IDM_OPEN,     "Open an existing item",
  201.       IDM_SAVE,     "Save an existing item",
  202.       IDM_SAVEAS,   "Save the current item with a new name",
  203.       IDM_PRINT,    "Prints the current item",
  204.       IDM_EXIT,     "Quits the application",
  205.       
  206.       IDM_UNDO,     "Reverse the last action",
  207.       IDM_CUT,      "Cuts the selection to the ClipBoard",
  208.       IDM_COPY,     "Copis the selection to the ClipBoard",
  209.       IDM_PASTE,    "Copies the selection from the ClipBoard",
  210.       IDM_CLEAR,    "Erases the currently selected item",
  211.       IDM_DELETE,   "Erases the currently selected item",
  212.       
  213.       SC_SIZE,      "Changes window size",
  214.       SC_MOVE,      "Changes window position",
  215.       SC_MINIMIZE,  "Reduces window to an icon",
  216.       SC_MAXIMIZE,  "Enlarges the active window to full size",
  217.       SC_CLOSE,     "Quits application",
  218.       SC_RESTORE,   "Restores window to normal size",
  219.       SC_TASKLIST,  "Switches to the Task Monitor",
  220.       IDM_TONY,     "Test Tony's Dialog Box Procedure"
  221.       
  222.     };
  223.     
  224.     static HMENU  hmenuEdit;
  225.     static HMENU  hmenuFile;
  226.     static HMENU  hmenuSys;
  227.  
  228.     
  229.     switch (message)
  230.       {
  231.       case WM_CREATE:
  232.         {
  233.         HMENU hmenu;
  234.         HWND  hwndParent;
  235.         
  236.         hwndParent = GetParent (hwnd);
  237.         hmenu = GetMenu (hwndParent);
  238.         hmenuFile = GetSubMenu (hmenu, 0);
  239.         hmenuEdit = GetSubMenu (hmenu, 1);
  240.         hmenuSys = GetSystemMenu (hwndParent, 0);
  241.         PostMessage (hwndParent, WM_CHAR, hmenuSys, 0L);
  242.         }
  243.         break;
  244.         
  245.                        
  246.       case WM_MENUSELECT:
  247.         {
  248.         char ach[50];
  249.         HDC hdc;
  250.         int isd;
  251.         int i;
  252.         RECT rClient;
  253.         WORD wFlag;
  254.         
  255.         wFlag = LOWORD (lParam);
  256.         
  257.         isd = 0;
  258.         if (wFlag == 0xffff)
  259.           isd = 0;
  260.         else if (wFlag & MF_POPUP)
  261.                {
  262.                if (hmenuSys == wParam)
  263.                  isd = 1;
  264.                if (hmenuFile == wParam)
  265.                  isd = 2;
  266.                if (hmenuEdit == wParam)
  267.                  isd = 3;
  268.                }
  269.         else
  270.                {
  271.                for (i = 0; i < COUNT; i++)
  272.                  {
  273.                  if (wParam == sd[i].wCode)
  274.                    {
  275.                    isd = i;
  276.                    break;
  277.                    }
  278.                  }
  279.                }
  280.         GetClientRect (hwnd, &rClient);
  281.         
  282.         hdc = GetDC (hwnd);
  283.         ExtTextOut (hdc,
  284.                     0,
  285.                     0,
  286.                     ETO_OPAQUE,
  287.                     &rClient,
  288.                     sd[isd].achMsg,
  289.                     lstrlen(sd[isd].achMsg),
  290.                     NULL);
  291.         ReleaseDC (hwnd,hdc);
  292.         }
  293.         break;
  294.         
  295.       default:
  296.         return (DefWindowProc (hwnd, message, wParam, lParam));
  297.         break;
  298.       }
  299.       
  300.     return 0L;
  301.   }              
  302.         
  303.         
  304. /****************************************************************************
  305.  
  306.     FUNCTION: Test2(HWND, unsigned, WORD, LONG)
  307.  
  308.     PURPOSE:  Processes messages for "About" dialog box
  309.  
  310.     MESSAGES:
  311.  
  312.         WM_INITDIALOG - initialize dialog box
  313.         WM_COMMAND    - Input received
  314.  
  315. ****************************************************************************/
  316.  
  317. BOOL FAR PASCAL Test2(hDlg, message, wParam, lParam)
  318. HWND hDlg;
  319. unsigned message;
  320. WORD wParam;
  321. LONG lParam;
  322. {
  323.  
  324.     char name[80];
  325.     char address[40];
  326.     char city[40];
  327.     char state[3];
  328.     char zip[5];
  329.     
  330.     
  331.     switch (message) {
  332.         case WM_INITDIALOG:
  333.           return (TRUE);
  334.  
  335.         case WM_COMMAND:
  336.           if (wParam == IDOK)
  337.             {
  338.             EndDialog(hDlg, TRUE);
  339.             return (TRUE);
  340.             }
  341.           else
  342.             if (wParam == IDCANCEL)
  343.              {
  344.              EndDialog(hDlg, FALSE);
  345.              return (FALSE);
  346.              }
  347.            break;
  348.     }
  349.     return (FALSE);
  350. }
  351.